<script>
import useUserStore from '@/stores/user'
import {mapActions} from "pinia";
import Upload from "@/components/Upload.vue";

export default {
  name: '404 not found',
  components: {Upload},
  beforeRouteEnter(to, from, next) {
    const store = useUserStore()
    console.log('beforeRouteEnter Guard')
    if (store.userLoggedIn) {
      next()
    } else {
      next({name: 'login'})
    }
  },
  data() {
    return {
      userStore: useUserStore()
    }
  },
  methods: {
    ...mapActions(useUserStore, {
      signOut: "logout"
    }),
    logout() {
      this.signOut()
      this.$router.push({name: 'login'})
    }
  }
}
</script>

<template>
  <main>
    hello world
    <button class="bg-cyan-200 rounded p-2" @click="logout">logout</button>
    <upload action="http://localhost:9090/upload" :on-success="(res)=>console.log(res)"></upload>
  </main>
</template>
